package com.TTBook.impl.author.daoImpl;

import com.TTBook.core.author.dao.AuthorDAO;
import com.TTBook.core.author.model.Author;
import com.TTBook.core.author.model.AuthorCriteria;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class AuthorDAOImpl extends SqlMapClientDaoSupport implements AuthorDAO {

    public AuthorDAOImpl() {
        super();
    }

    public int countByCriteria(AuthorCriteria criteria) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("ts_author.countByCriteria", criteria);
        return count.intValue();
    }

    public int deleteByCriteria(AuthorCriteria criteria) {
        int rows = getSqlMapClientTemplate().delete("ts_author.deleteByCriteria", criteria);
        return rows;
    }

    public void insert(Author record) {
        getSqlMapClientTemplate().insert("ts_author.insert", record);
    }

    public void insertSelective(Author record) {
        getSqlMapClientTemplate().insert("ts_author.insertSelective", record);
    }

    public List selectByCriteria(AuthorCriteria criteria) {
        List list = getSqlMapClientTemplate().queryForList("ts_author.selectByCriteria", criteria);
        return list;
    }

    public int updateByCriteriaSelective(Author record, AuthorCriteria criteria) {
        UpdateByCriteriaParms parms = new UpdateByCriteriaParms(record, criteria);
        int rows = getSqlMapClientTemplate().update("ts_author.updateByCriteriaSelective", parms);
        return rows;
    }

    public int updateByCriteria(Author record, AuthorCriteria example) {
        UpdateByCriteriaParms parms = new UpdateByCriteriaParms(record, example);
        int rows = getSqlMapClientTemplate().update("ts_author.updateByCriteria", parms);
        return rows;
    }

    private static class UpdateByCriteriaParms extends AuthorCriteria {
        private Object record;

        public UpdateByCriteriaParms(Object record, AuthorCriteria criteria) {
            super(criteria);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }
}